package com.qikux.vo;

import java.util.Objects;

public class R<T> {

    private String status ;

    private String message ;

    private T data ;

    private R() {}

    public static <T> R<T> ok() {
        R<T> ret = new R<>() ;
        ret.status = RType.SUCCESS.code ;
        return ret ;
    }

    public static <T> R<T> fail(String message) {
        R<T> ret = new R<>() ;
        ret.status = RType.FAIL.code;
        ret.message = message ;
        return ret ;
    }

    public static <T> R<T> of(RType rType, String message) {
        R<T> ret = new R<>() ;
        ret.status = rType.code;
        ret.message = message ;
        return ret ;
    }

    public R<T> message(String message) {
        this.message = message ;
        return this ;
    }

    public R<T> data(T data) {
        this.data = data ;
        return this ;
    }

    public boolean isSuccess() {
        return Objects.equals(this.status, RType.SUCCESS.code);
    }

    public static enum RType {

        SUCCESS("1000") , FAIL("2000"),  ERROR("2001") ;

        private final String code ;

        RType(String code) {
            this.code = code ;
        }

        @Override
        public String toString() {
            return this.code ;
        }
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
